<template>
  <view class="good-item">
    <!-- 添加一个radio -->
      <radio :checked="good.goods_state" color="#C00000" @click="handlerGoodsItem" v-if="radioShow" />
    <!-- 左侧 -->
    <view class="good-item-left" @click="click">
      <image :src="good.goods_small_logo || defaultPic" class="good-pic"></image>
    </view>
    <!-- 右侧 -->
    <view class="good-item-right" @click="click">
      <view class="good-name">{{good.goods_name}}</view>
      <view class="good-content">
        <text class="good-content-price">¥{{good.goods_price | toFixed}}</text>
        <!-- 数字输入框 -->
        <uni-number-box v-model="good.goods_count" v-if="numShow" min="1" @change="numChange"></uni-number-box>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name: "my-goodlist",
    props: {
      good: {
        type: Object,
        default: {}
      },
      radioShow: {
        type: Boolean,
        default: false
      },
      numShow: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
      };
    },
    filters: {
      toFixed(num) {
        // return num.toFixed(2)
        // 更严谨的写法
        return Number(num).toFixed(2)
      }
    },
    methods: {
      click() {
        this.$emit('click')
      },
      handlerGoodsItem() {
        const goodInfo = {
          goods_id: this.good.goods_id,
          goods_state: this.good.goods_state
        }
        this.$emit('changeStatus', goodInfo)
      },
      numChange(val) {
        const goodInfo = {
            goods_id: this.good.goods_id,
            goods_count: +val // 可以保证是数字
          }
          this.$emit('changeNum', goodInfo)    
      }
    }
  }
</script>

<style lang="scss">
  .good-item {
    // height: 500px;
    display: flex;
    padding: 10px 5px;
    border-bottom: 1px solid #E5E5E5;
    // justify-content: space-between;
    align-items: center;
    .good-item-left {
      margin-right: 5px;

      .good-pic {
        width: 100px;
        height: 100px;
        // 消除图片的下方空袭
        display: block;
      }
    }

    .good-item-right {
      display: flex;
      flex: 1;
      flex-direction: column;
      justify-content: space-between;

      .good-name {
        font-size: 13px;
      }

      .good-content {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-top: 10px;
        .good-content-price {
          font-size: 16px;
          color: #c00000;
        }
      }

    }
  }
</style>
